/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-04-21
 * Time:21:54
 */

/**
 * BM14 链表的奇偶重排
 */

public class oddEvenList {
    public ListNode oddEvenList (ListNode head) {
        if (head == null) return null;
        ListNode odd = head;
        ListNode even = head.next;
        ListNode evenHead = even;//记录偶数节点的起点，无其他多余用处
        while (even != null && even.next != null) {
            odd.next = even.next;
            odd = odd.next;
            even.next = odd.next;
            even = even.next;
        }
        odd.next = evenHead;
        return head;
    }
}
